package mapred.config;

import java.io.IOException;

import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.mapred.JobConf;

public class JobConfig implements IConfig {

    private static final String NULL = "(null)";
    
    private JobConf conf;

    public JobConfig() {
        this(new JobConf(JobConfig.class));
    }

    public JobConfig(JobConf conf) {
        this.conf = conf;
    }

    public JobConf getJobConf() {
        return conf;
    }

    public void set(String key, Object value) {
        this.conf.set(normalizeKey(key), value.toString());
    }

    public boolean containsKey(String key) {
        String v = this.get(normalizeKey(key));
        return (v != null && !NULL.equals(v));
    }

    public String get(String key) {
        return this.conf.get(normalizeKey(key));
    }

    public String normalizeKey(String key) {
        return key.toLowerCase();
    }

    public void remove(String key) {
        this.set(key, NULL);
    }

    public FileSystem getFileSystem() throws IOException {
        return FileSystem.get(this.conf);
    }

}
